package com.inews.business.entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

// TODO: Auto-generated Javadoc
/**
 * 系统资源实体.
 */
@Entity
@Table(name="tbl_sys_resource")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class TblSysResource extends TblBasePo implements Serializable{

	private static final long serialVersionUID = -6716116635654730576L;
	
	/** 父级资源. */
	private TblSysResource parentResource;
	
	/** 子级资源. */
	private Set<TblSysResource> childResources = new HashSet<TblSysResource>();
	
	/** 对应角色资源关系. */
	private Set<TblSysRoleResource> roleResources = new HashSet<TblSysRoleResource>();
	
	/** 资源Id. */
	private String resourceId;
	
	/** 资源名称. */
	private String resourceName;
	
	/** 资源路径. */
	private String resourceUrl;
	
	/** 排序号(序号越大，菜单显示越下面). */
	private String orderNum;
	
	/** 显示类型
	 *  0: 页面级别
	 *  1：按钮级别 . */
	private String showType;
	
	@ManyToOne(cascade=CascadeType.REFRESH, fetch=FetchType.LAZY)
	@JoinColumn(name="father_id")
	public TblSysResource getParentResource() {
		return parentResource;
	}

	public void setParentResource(TblSysResource parentResource) {
		this.parentResource = parentResource;
	}

	@OneToMany(cascade={CascadeType.REFRESH}, mappedBy="parentResource", fetch=FetchType.LAZY)
	@OrderBy(value="resourceId")
	public Set<TblSysResource> getChildResources() {
		return childResources;
	}

	public void setChildResources(Set<TblSysResource> childResources) {
		this.childResources = childResources;
	}
	
	@OneToMany(cascade={CascadeType.REFRESH, CascadeType.MERGE},mappedBy="resource")
	public Set<TblSysRoleResource> getRoleResources() {
		return roleResources;
	}

	public void setRoleResources(Set<TblSysRoleResource> roleResources) {
		this.roleResources = roleResources;
	}

	@Id
	@Column(name="resource_id", nullable=false, length=40)
	public String getResourceId() {
		return resourceId;
	}

	public void setResourceId(String resourceId) {
		this.resourceId = resourceId;
	}

	@Column(name="resource_name", nullable=false, length=40)
	public String getResourceName() {
		return resourceName;
	}

	public void setResourceName(String resourceName) {
		this.resourceName = resourceName;
	}

	@Column(name="resource_url", nullable=false, length=100)
	public String getResourceUrl() {
		return resourceUrl;
	}

	public void setResourceUrl(String resourceUrl) {
		this.resourceUrl = resourceUrl;
	}

	@Column(name="order_num", nullable=false, length=5)
	public String getOrderNum() {
		return orderNum;
	}

	public void setOrderNum(String orderNum) {
		this.orderNum = orderNum;
	}

	@Column(name="show_type", nullable=false, length=1)
	public String getShowType() {
		return showType;
	}

	public void setShowType(String showType) {
		this.showType = showType;
	}
	
}
